package com.shopManager.contoller.shopReduce;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shopReduce.bean.ShopReduce;
import com.shopReduce.feign.ShopReduceFeign;

import shopBean.common.bean.RestResult;
import shopBean.common.responseCode.Status;
import shopBean.common.utils.RestResultGenerator;
@Controller
@RequestMapping("/shopReduceManager")
public class ShopReduceManagerContoller {
	@Autowired
	ShopReduceFeign shopReduceFeign;
	@ResponseBody
	@RequestMapping("/insert.shtml")
	public RestResult insert(ShopReduce shopReduce) {
		if(StringUtils.isBlank(shopReduce.getBeginDate())) {
			return RestResultGenerator.genError("商品优惠方案开始时间不能为空");
		}
		if(StringUtils.isBlank(shopReduce.getExpireDate())) {
			return RestResultGenerator.genError("商品优惠方案过期时间不能为空");
		}
		if(StringUtils.isBlank(shopReduce.getReduceId())) {
			return RestResultGenerator.genError("优惠方案id不能为空");
		}
		if(StringUtils.isBlank(shopReduce.getShopId())) {
			return RestResultGenerator.genError("商品id不能为空");
		}
		if(shopReduce.getSort() == null) {
			return RestResultGenerator.genError("优惠顺序不能为空");
		}
		RestResult result = shopReduceFeign.insert(shopReduce);
		if(result == null) {
			return RestResultGenerator.genError("商品优惠方案添加失败,服务不可用");
		}
		return result;
	}

	@RequestMapping("/listManager.shtml")
	public RestResult list(ShopReduce shopReduce) {

		return shopReduceFeign.list(shopReduce);
	}
	@ResponseBody
	@RequestMapping("/get.shtml")
	public RestResult get(@RequestParam(value = "id") String id) {
		return shopReduceFeign.getApi(id);
	}
	@ResponseBody
	@RequestMapping("/updateById.shtml")
	public RestResult updateById(ShopReduce shopReduce) {
		return shopReduceFeign.updateById(shopReduce);
	}
	@ResponseBody
	@RequestMapping("/deleteById.shtml")
	public RestResult deleteById(@RequestParam(value = "id") String id) {
		return shopReduceFeign.deleteById(id);

	}
}
